#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/hash_policy.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ps putchar(' ')
#define pe putchar('\n')
#define int long long
#define eb emplace_back
#define pi pair<int, int>
#define mk make_pair
#define fi first
#define se second
#define Ad tr[p].ad
// #define Ad t[p].ad
// #define ls p << 1
// #define rs p << 1 | 1
#define ls tr[p].son[0]
#define rs tr[p].son[1]
// #define ls t[p].son[0]
// #define rs t[p].son[1]
#define len (r - l + 1)
#define mid ((l + r) >> 1)
using namespace std;
// using namespace __gnu_pbds;
inline int read()
{
    int f = 0, ans = 0;
    char c = getchar();
    while (!isdigit(c))
        f |= c == '-', c = getchar();
    while (isdigit(c))
        ans = (ans << 3) + (ans << 1) + c - 48, c = getchar();
    return f ? -ans : ans;
}
void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}
const int N = 4e5 + 5, M = N << 2, inf = 1e18, mod = 1e9 + 7;
int n, a[N];
signed main()
{
    freopen("kte.in", "r", stdin);
    freopen("kte.out", "w", stdout);
    int T = read();
    while (T--)
    {
        int x = read();
        if (count(a + 1, a + n + 1, x) == 0)
            a[++n] = x, sort(a + 1, a + n + 1);
        else
            for (int i = 1; i <= n; ++i)
                if (a[i] == x)
                {
                    for (int j = i; j < n; ++j)
                        a[j] = a[j + 1];
                    --n;
                    break;
                }
        int ans = 0;
        for (int i = 1, now = 0, mn = 0, mx = 0; i <= n; ++i)
        {
            mn += a[i], mx += a[n - i + 1];
            ans += mx - max(now, mn), now = mx;
        }
        write(ans), pe;
    }
    return 0;
}
